package com.baidu.controller;


import com.alibaba.dubbo.config.annotation.Reference;
import com.baidu.constant.MessageConstant;
import com.baidu.entity.PageResult;
import com.baidu.entity.QueryPageBean;
import com.baidu.entity.Result;
import com.baidu.pojo.Disease;
import com.baidu.service.DiseaseService;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/disease")
public class DiseaseController {

	@Reference
	private DiseaseService diseaseService;

//查
	@RequestMapping("/pageQuery")
	public PageResult pageQuery(@RequestBody QueryPageBean queryPageBean){
		PageResult pageResult = diseaseService.pageQuery(queryPageBean);
		return pageResult;

	}


//删
	@DeleteMapping("/delete/{id}")
	public Result delete(@PathVariable Integer id){

		try {
			diseaseService.delete(id);
			return new Result(true, MessageConstant.DELETE_DISEASE_SUCCESS);
		} catch (Exception e) {
				return  new Result(false,MessageConstant.DELETE_DISEASE_FAIL);
		}


	}

//添加
	@RequestMapping("/add")
	public Result add(@RequestBody Disease disease) {//传递过来的是json、对象

		try {
			diseaseService.add(disease);
			return 	new Result(true, MessageConstant.ADD_DISEASE_SUCCESS);

		} catch (Exception e) {
			return 	new Result(false, MessageConstant.ADD_DISEASE_FAIL);
		}


	}

//	回显单个
@GetMapping("/findById/{id}")
public Result findById(@PathVariable Integer id){
	try {
		Disease disease= diseaseService.findById(id);
		return new Result(true,"",disease);
	} catch (Exception e) {
		return new Result(false,"");
	}
}

//编辑
@PostMapping("/edit")
public Result editCheckItem(@RequestBody Disease disease){

	try {
		diseaseService.edit(disease);
		return new Result(true, MessageConstant.EDIT_DISEASE_SUCCESS);
	} catch (Exception e) {
		return new Result(false,MessageConstant.EDIT_DISEASE_FAIL);
	}


}




}
